
package data.datas;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

import network.e2e.FrameReader;
import network.e2e.FrameWriter;
import network.link.FrameInputStream;
import network.link.FrameOutputStream;

import org.junit.Assert;
import org.junit.Test;

import stalker.Stalker;
import data.content.Content;
import data.content.ContentSentence;


public class DatasParserTest {
  
  @Test
  public void testCompleteHistoryDatas() throws IOException {
    Content test = new ContentSentence("Irvan ganteng!");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    FrameWriter fw = new FrameWriter(new FrameOutputStream(os));
    
    Datas dts = new CompleteHistoryDatas();
    dts.addData(Stalker.GUEST_STALKER, test);
    
    DatasParser.send(dts, fw);
    
    FrameReader fr = new FrameReader(new FrameInputStream(new ByteArrayInputStream(os.toByteArray())));
    
    System.out.println(os.toString());
    
    Datas stalk = DatasParser.retrieve(fr);
    
    Assert.assertEquals(stalk, dts);
  }
  
  @Test
  public void testNoHistoryDatas() throws IOException {
    Content test = new ContentSentence("Irvan ganteng!");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    FrameWriter fw = new FrameWriter(new FrameOutputStream(os));
    
    Datas dts = new NoHistoryDatas();
    dts.addData(Stalker.GUEST_STALKER, test);
    
    DatasParser.send(dts, fw);
    
    FrameReader fr = new FrameReader(new FrameInputStream(new ByteArrayInputStream(os.toByteArray())));
    
    System.out.println(os.toString());
    
    Datas stalk = DatasParser.retrieve(fr);
    
    Assert.assertEquals(stalk, dts);
  }
  
}
